package com.zzptc.ly.a12_1;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import java.util.ArrayList;


public class FirstFragment extends Fragment {
    LineChart lineChart;

    public FirstFragment() {
    }


    public static FirstFragment newInstance(String param1, String param2) {
        FirstFragment fragment = new FirstFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.fragment_first, container, false);

        initView(view);

        ArrayList<Entry> list1 = new ArrayList<>();
        list1.add(new Entry(1, 9));
        list1.add(new Entry(2, 8));
        list1.add(new Entry(3, 5));
        list1.add(new Entry(4, 5));
        list1.add(new Entry(5, 3));
        ArrayList<Entry> list2 = new ArrayList<>();
        list2.add(new Entry(1, 7));
        list2.add(new Entry(2, 6));
        list2.add(new Entry(3, 9));
        list2.add(new Entry(4, 9));
        list2.add(new Entry(5, 1));
        LineDataSet lineDataSet = new LineDataSet(list1, null);
        lineDataSet.setColor(Color.BLUE);
        LineDataSet lineDataSet1 = new LineDataSet(list2, null);
        lineDataSet.setColor(Color.RED);
        ArrayList<ILineDataSet> list_linDataset = new ArrayList<>();
        list_linDataset.add(lineDataSet);
        list_linDataset.add(lineDataSet1);
        LineData lineData = new LineData(list_linDataset);
        lineChart.setData(lineData);
        XAxis xAxis = lineChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        return view;
    }
    private void initView(View view) {
        lineChart=view.findViewById(R.id.line_Chart);
    }

}
